#include <bits/stdc++.h>

using namespace std;

typedef struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
} TreeNode;

class Solution
{
public:
    TreeNode *insertIntoMaxTree(TreeNode *root, int val)
    {
        TreeNode *parent = nullptr;
        TreeNode *cur = root;
        while (cur)
        {
            if (val > cur->val)
            {
                if (!parent)
                {
                    return new TreeNode(val, root, nullptr);
                }
                TreeNode *node = new TreeNode(val, cur, nullptr);
                parent->right = node;
                return root;
            }
            else
            {
                parent = cur;
                cur = cur->right;
            }
        }
        parent->right = new TreeNode(val);
        return root;
    }
};

int main(int argc, char const *argv[])
{
    /* code */
    return 0;
}
